<?php

/**
 * 用户展示控制器   前台
 */

class UserController extends Controller {

	private $model;

	public function __init() {
		$this -> model = K('User');
	}

	/**
	 * 默认显示前台用户
	 */
	public function index() {
		$flag = Q('get.s', 0, 'intval');

		//默认显示前台用户列表
		$userCount = M('user') -> where('is_admin=' . $flag) -> count();
		//显示分页
		if ($userCount > 14) {
			$page = new Page($userCount, 14, 10);
			$users = $this -> model -> findUser(0, $page -> limit());
			$this -> assign('page', $page -> show(1));
			$this -> assign('users', $users);
		} else {
			$users = $this -> model -> findUser($flag);
			$this -> assign('users', $users);
		}

		$this -> display();
	}

	/**
	 * 将一个用户锁定或者解除锁定
	 */
	public function islock() {
		//用户UID
		$uid 	= Q('get.uid');
		//锁定或解锁  1为锁定 0为解锁
		$lock 	= Q('get.lock');
		
		if($this->model->isLock($uid,$lock)){
			$this->ajax(1);
		}else{
			$this->ajax(0);
		}
	}
	
	/**
	 * 删除一个指定uid的用户
	 */
	 public function deluser(){
	 	$uid = Q('get.uid');
		if($this->model->delete("uid={$uid}")){
			$this->ajax(1);
		}else{
			$this->ajax(0);
		}
	 }
	 
	 /**
	  * 修改密码方法
	  */
	  public function cpwd(){
		if($this->model->cpwd()){
			$this->ajax(1);
		}else{
			$this->ajax(0);
		}
	  }

}
